package com.heima.wemedia.controller;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemeda.dto.WmMaterialDto;
import com.heima.model.wemeda.entity.WmMaterial;
import com.heima.wemedia.dao.WmMaterialDao;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 自媒体素材表(WmMaterial)表控制层
 *
 * @author makejava
 * @since 2022-04-10 16:16:26
 */
@RestController
@RequestMapping("/api/v1/material/")
@Api(value = "自媒体素材管理API",tags = "自媒体素材管理")
public class WmMaterialController {
    /**
     * 服务对象
     */
    @Resource
    private WmMaterialService wmMaterialService;

    @Resource
    private WmMaterialDao wmMaterialDao;


    //上传图片保存在minio中
    @ApiOperation(value = "素材上传")
    @PostMapping("upload_picture")
    public ResponseResult<String> upload_picture(MultipartFile multipartFile) {
        return wmMaterialService.uploadPicture(multipartFile);
    }



    //分页查询
    @ApiOperation(value = "素材列表查询")
    @PostMapping("list")
    public ResponseResult queryByPage(@RequestBody WmMaterialDto wmMaterialDto) {
        return wmMaterialService.queryByPage(wmMaterialDto);
    }

    //删除素材
    @ApiOperation(value = "素材删除")
    @GetMapping("del_picture/{id}")
    public ResponseResult  deleteMaterial(@PathVariable Long id){
        wmMaterialDao.deleteById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    //素材收藏
    @ApiOperation(value = "素材收藏")
    @GetMapping("collect/{id}")
    public  ResponseResult  updateMaterial(@PathVariable Long id){
        ResponseResult responseResult = wmMaterialService.updateBycollect(id);
        return  responseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    //取消收藏
    @ApiOperation(value = "素材取消删除")
    @GetMapping("cancel_collect/{id}")
    public  ResponseResult  updateNoMaterial(@PathVariable Long id){
        ResponseResult responseResult = wmMaterialService.updateBycancel(id);
        return  responseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }



}

